/**
 * 
 */
package com.google.code.rookery.converter;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author Xerox
 *
 */
public class CalendarToDateConverter extends InstanceConverter {

  /**
   * No-arg constructor
   */
  public CalendarToDateConverter() {
  }

  /* (non-Javadoc)
   * @see com.google.code.rookery.converter.InstanceConverter#convert(java.lang.Object)
   */
  @Override
  public Object convert(Object obj) {
    Object ret = null;
    if(obj instanceof Calendar){
      ret = convert((Calendar)obj);
    }
    return ret;
  }

  /**
   * Convert a calendar to a date
   * @param cal the calendar
   * @return the date
   */
  public Date convert(Calendar cal) {
    Date ret = null;
    if(cal!=null){
      ret = cal.getTime();
    }
    return ret;
  }

  /**
   * Convert a Gregorian calendar to a date
   * @param cal the calendar
   * @return the date
   */
  public Date convert(GregorianCalendar cal) {
    return convert((Calendar) cal);
  }
}
